package com.geekstudy.week6.tool;

import java.sql.SQLException;
import java.sql.Statement;

public class JdbcTool {

    public boolean createTable(String tableName, Statement statement) throws SQLException {

        //String createTableSql = "create table if not exists " + tableName
        //        + "(id varchar(64) primary key not null, "
        //        + "name varchar(64), "
        //        + "remark varchar(512), "
        //        + "index index_name(name))";
        // 默认 ENGINE=InnoDB
        // boolean result = statement.execute(createTableSql);
        // statement.execute("drunk from " + tableName);
        boolean result = createTable(tableName, statement, "InnoDB");
        return result;
    }

    public boolean createTable(String tableName, Statement statement, String engine) throws SQLException {
        String createTableSql = "create table if not exists " + tableName
                + "(id varchar(64) primary key not null, "
                + "name varchar(64), "
                + "remark varchar(512), "
                + "index index_name(name)) ENGINE = " + engine;
        boolean result = statement.execute(createTableSql);
        statement.execute("truncate table " + tableName);
        return result;
    }
}
